﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GPMS.Model;

namespace GPMS.Web.Controllers
{
    public class UserInfoController : BaseController
    {
        //
        // GET: /UserInfo/

        public ActionResult UserList()
        {
            Guid id = GPMS.BLL.AccountHelper.GetLoginUserID(Request);
            var list = gpmsDb.UserInfos.FirstOrDefault(u=>u.UserID == id).ToString();//用户个人信息
            var GPlist = gpmsDb.GraduationProjects.FirstOrDefault(g=>g.GPID == gpmsDb.GPSelections.FirstOrDefault(s=>s.UserID == id).GPID).ToString();//用户选题信息
            var Plist = gpmsDb.ProjectPlans.FirstOrDefault(p => p.SelectionID == gpmsDb.GPSelections.FirstOrDefault(s => s.UserID == id).SelectionID).ToString();//用户计划信息
            var Paperslist = gpmsDb.AnswerGroups.FirstOrDefault(a=>a.Students.UserID == id).ToString();//用户答辩信息
            return View(list+GPlist+Plist);
        }

        public ActionResult UserEdit(Guid id)
        {
            try
            {
                UserInfo user = gpmsDb.UserInfos.FirstOrDefault(u => u.UserID == id);
                UpdateModel(user);
                gpmsDb.SaveChanges();
                return Success("修改成功");
            }
            catch(Exception ex)
            {
                return   JsonError("出错"+ex.Message);
            }
        }
    }
}
